package org.skill.panel;

import java.awt.Dimension;
import java.awt.Graphics;
import java.math.BigDecimal;
import java.util.Map;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import org.come.Jpanel.CharacterMeridiansMainJpanel;
import org.come.bean.ConfigureBean;
import org.come.bean.LoginResult;
import org.come.model.Configure;
import org.come.until.CutButtonImage;
import org.come.until.UserMessUntil;
import org.skill.btn.SkillMainBtn;

import com.tool.btn.FormsOnOffBtn;
import com.tool.role.RoleData;
import com.updateNew.MyIsif;

 

/**
 * 技能主面板
 * 
 * @author Administrator
 * 
 */
public class SkillMainPanel extends JPanel {
    private SkillMainBtn[] mainBtns;
    private SkillSMGatePanel divisionGatePanel;
    private CopyOfSkillTYCPanel copyOfSkillTYCPanel;
    private CharacterMeridiansMainJpanel meridiansMainJpanel;
    private SkillSMGatePanel2 divisionGatePanel2;
    private String jmkg,fmkg,tyckg;
    public SkillMainPanel() {
    	ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
    	Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
    	Configure configure = item.get(new BigDecimal(1));
    	jmkg = configure.getJmgnkg();
    	fmkg = configure.getFmgnkg();
        tyckg = configure.getDshsz();
        if("水墨UI".equals(MyIsif.getStyle())) {

            this.setPreferredSize(new Dimension(602, 425));
            this.setOpaque(false);
            this.setLayout(null);
            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 82);
            offBtn.setBounds(602 - 37, 10, 25, 25);
            this.add(offBtn);
            if("3".equals(configure.getLzjskg())) {
                mainBtns = new SkillMainBtn[1];
            }else {
                if("开".equals(tyckg) && "开".equals(jmkg) && "开".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[4];
                }else if("开".equals(tyckg) && "开".equals(jmkg) && "关".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[3];
                }else if("开".equals(tyckg) && "关".equals(jmkg) && "开".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[3];
                }else if("关".equals(tyckg) && "开".equals(jmkg) && "开".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[3];
                }else if("关".equals(tyckg) && "关".equals(jmkg) && "开".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[2];
                }else if("关".equals(tyckg) && "开".equals(jmkg) && "关".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[2];
                }else if("开".equals(tyckg) && "关".equals(jmkg) && "关".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[2];
                }else if("关".equals(tyckg) && "关".equals(jmkg) && "关".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[1];
                }
            }
            for (int i = 0; i < mainBtns.length; i++) {
                mainBtns[i] = new SkillMainBtn(null, 1, i, this);
                mainBtns[i].setBounds(70 + 80 * i, 23, 75, 33);
                this.add(mainBtns[i]);
            }
            divisionGatePanel = new SkillSMGatePanel();
            divisionGatePanel.setVisible(false);
            this.add(divisionGatePanel);
            copyOfSkillTYCPanel = new CopyOfSkillTYCPanel();
            copyOfSkillTYCPanel.setVisible(false);
            this.add(copyOfSkillTYCPanel);
            meridiansMainJpanel = new CharacterMeridiansMainJpanel();
            meridiansMainJpanel.setVisible(false);
            this.add(meridiansMainJpanel);
            //法门
            divisionGatePanel2 = new SkillSMGatePanel2();
            divisionGatePanel2.setVisible(false);
            this.add(divisionGatePanel2);
        }else{
            this.setPreferredSize(new Dimension(576, 447));
            this.setOpaque(false);
            this.setLayout(null);
            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/hongmu/2/8_jpg.button.btn_close.jpg", 1, 82);
            offBtn.setBounds(550, 0, 23, 23);
            this.add(offBtn);
            if("3".equals(configure.getLzjskg())) {
                mainBtns = new SkillMainBtn[1];
            }else {
                if("开".equals(jmkg) && "开".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[4];
                }else if("开".equals(jmkg) && "关".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[3];
                }else if("关".equals(jmkg) && "开".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[3];
                }else if("关".equals(jmkg) && "关".equals(fmkg)) {
                    mainBtns = new SkillMainBtn[2];
                }
            }
            for (int i = 0; i < mainBtns.length; i++) {
                mainBtns[i] = new SkillMainBtn("inkImg/hongmu/soaringSkill/选项卡_师门_未选中_w80,h120.png", 1, i, this);
                mainBtns[i].setBounds(28 + 82 * i, 31, 80, 40);
                this.add(mainBtns[i]);
            }
            divisionGatePanel = new SkillSMGatePanel();
            divisionGatePanel.setVisible(false);
            this.add(divisionGatePanel);
            copyOfSkillTYCPanel = new CopyOfSkillTYCPanel();
            copyOfSkillTYCPanel.setVisible(false);
            this.add(copyOfSkillTYCPanel);
            meridiansMainJpanel = new CharacterMeridiansMainJpanel();
            meridiansMainJpanel.setVisible(false);
            this.add(meridiansMainJpanel);
            //法门
            divisionGatePanel2 = new SkillSMGatePanel2();
            divisionGatePanel2.setVisible(false);
            this.add(divisionGatePanel2);
        }

    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if("水墨UI".equals(MyIsif.getStyle())) {

            if (icon == null) {
                icon = new ImageIcon("inkImg/newbackground/B220.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 602, 425, this);
        }else{
            if (icon == null) {
                icon = new ImageIcon("inkImg/hongmu/soaringSkill/技能w576,h447.png");
            }
            g.drawImage(this.icon.getImage(), 0, 0, 576, 447, this);
        }
    }

    private int typeBtn;

    /** 选项按钮点击 */
    public void changeBtnPanel(int typeBtn) {
        // if (this.typeBtn==typeBtn) {return;}
        this.typeBtn = typeBtn;
        if("水墨UI".equals(MyIsif.getStyle())) {

            for (int i = 0; i < mainBtns.length; i++) {
                try {
                    mainBtns[i].setIcons(CutButtonImage.cuts(getBtnPanelPath(i, i == this.typeBtn)));
                    if("开".equals(tyckg) && "开".equals(jmkg) && "开".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        } else if (i == 1) {
                            copyOfSkillTYCPanel.setVisible(i == this.typeBtn);
                        }else if(i == 2){
                            meridiansMainJpanel.setVisible(i == this.typeBtn);
                        }else if(i == 3){
                            divisionGatePanel2.setVisible(i == this.typeBtn);
                        }
                    }else if("开".equals(tyckg) && "开".equals(jmkg) && "关".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        } else if (i == 1) {
                            copyOfSkillTYCPanel.setVisible(i == this.typeBtn);
                        }else if(i == 2){
                            meridiansMainJpanel.setVisible(i == this.typeBtn);
                        }
                    }else if("开".equals(tyckg) && "关".equals(jmkg) && "开".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        } else if (i == 1) {
                            copyOfSkillTYCPanel.setVisible(i == this.typeBtn);
                        }else if(i == 2){
                            divisionGatePanel2.setVisible(i == this.typeBtn);
                        }
                    }else if("关".equals(tyckg) && "开".equals(jmkg) && "开".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        } else if (i == 1) {
                            meridiansMainJpanel.setVisible(i == this.typeBtn);
                        }else if(i == 2){
                            divisionGatePanel2.setVisible(i == this.typeBtn);
                        }
                    }else if("关".equals(tyckg) && "关".equals(jmkg) && "开".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        } else if (i == 1) {
                            divisionGatePanel2.setVisible(i == this.typeBtn);
                        }
                    }else if("关".equals(tyckg) && "开".equals(jmkg) && "关".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        } else if (i == 1) {
                            meridiansMainJpanel.setVisible(i == this.typeBtn);
                        }
                    }else if("开".equals(tyckg) && "关".equals(jmkg) && "关".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        } else if (i == 1) {
                            copyOfSkillTYCPanel.setVisible(i == this.typeBtn);
                        }
                    }else if("关".equals(tyckg) && "关".equals(jmkg) && "关".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if("开".equals(tyckg) && "开".equals(jmkg) && "开".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                } else if (this.typeBtn == 1) {
                    copyOfSkillTYCPanel.changeBtnPanel(0);
                }else if(this.typeBtn == 2){
                    meridiansMainJpanel.refreshAllAttribute();
                }else if(this.typeBtn == 3){
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel2.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                }
            }else if("开".equals(tyckg) && "开".equals(jmkg) && "关".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                } else if (this.typeBtn == 1) {
                    copyOfSkillTYCPanel.changeBtnPanel(0);
                }else if(this.typeBtn == 2){
                    meridiansMainJpanel.refreshAllAttribute();
                }
            }else if("开".equals(tyckg) && "关".equals(jmkg) && "开".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                } else if (this.typeBtn == 1) {
                    copyOfSkillTYCPanel.changeBtnPanel(0);
                }else if(this.typeBtn == 2){
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel2.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                }
            }else if("关".equals(tyckg) && "开".equals(jmkg) && "开".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                } else if (this.typeBtn == 1) {
                    meridiansMainJpanel.refreshAllAttribute();
                }else if(this.typeBtn == 2){
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel2.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                }
            }else if("关".equals(tyckg) && "关".equals(jmkg) && "开".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                } else if (this.typeBtn == 1) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel2.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                }
            }else if("关".equals(tyckg) && "开".equals(jmkg) && "关".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                } else if (this.typeBtn == 1) {
                    meridiansMainJpanel.refreshAllAttribute();
                }
            }else if("开".equals(tyckg) && "关".equals(jmkg) && "关".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                } else if (this.typeBtn == 1) {
                    copyOfSkillTYCPanel.changeBtnPanel(0);
                }
            }else if("关".equals(tyckg) && "关".equals(jmkg) && "关".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                }
            }
        }else{
            for (int i = 0; i < mainBtns.length; i++) {
                try {
                    mainBtns[i].setIcons(CutButtonImage.cuts(getBtnPanelPath(i, i == this.typeBtn)));

                    if("开".equals(jmkg) && "开".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        } else if (i == 1) {
                            copyOfSkillTYCPanel.setVisible(i == this.typeBtn);
                        }else if(i == 2){
                            meridiansMainJpanel.setVisible(i == this.typeBtn);
                        }else if(i == 3){
                            divisionGatePanel2.setVisible(i == this.typeBtn);
                        }
                    }else if("开".equals(jmkg) && "关".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        } else if (i == 1) {
                            copyOfSkillTYCPanel.setVisible(i == this.typeBtn);
                        }else if(i == 2){
                            meridiansMainJpanel.setVisible(i == this.typeBtn);
                        }
                    }else if("关".equals(jmkg) && "开".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        } else if (i == 1) {
                            copyOfSkillTYCPanel.setVisible(i == this.typeBtn);
                        }else if(i == 2){
                            divisionGatePanel2.setVisible(i == this.typeBtn);
                        }
                    }else if("关".equals(jmkg) && "关".equals(fmkg)) {
                        if (i == 0) {
                            divisionGatePanel.setVisible(i == this.typeBtn);
                        } else if (i == 1) {
                            copyOfSkillTYCPanel.setVisible(i == this.typeBtn);
                        }
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }


            if("开".equals(jmkg) && "开".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                } else if (this.typeBtn == 1) {
                    copyOfSkillTYCPanel.changeBtnPanel(0);
                }else if(this.typeBtn == 2){
                    meridiansMainJpanel.refreshAllAttribute();
                }else if(this.typeBtn == 3){
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel2.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                }
            }else if("开".equals(jmkg) && "关".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                } else if (this.typeBtn == 1) {
                    copyOfSkillTYCPanel.changeBtnPanel(0);
                }else if(this.typeBtn == 2){
                    meridiansMainJpanel.refreshAllAttribute();
                }
            }else if("关".equals(jmkg) && "开".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                } else if (this.typeBtn == 1) {
                    copyOfSkillTYCPanel.changeBtnPanel(0);
                }else if(this.typeBtn == 2){
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel2.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                }
            }else if("关".equals(jmkg) && "关".equals(fmkg)) {
                if (this.typeBtn == 0) {
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    divisionGatePanel.getRaceSkillPanel(loginResult.getRace_id(), loginResult.getSex());
                } else if (this.typeBtn == 1) {
                    copyOfSkillTYCPanel.changeBtnPanel(0);
                }
            }
        }
    }

    /** 获取选项卡路径 ture选中 */
    public String getBtnPanelPath(int btn, boolean is) {
        StringBuffer buffer = new StringBuffer();
        int num = 0;
        if("水墨UI".equals(MyIsif.getStyle())) {

            buffer.append("inkImg/old/2/K100");
            if("开".equals(tyckg) && "开".equals(jmkg) && "开".equals(fmkg)) {
                if(btn == 0){
                    num = 1;
                }else if(btn == 1){
                    num = 3;
                }else if(btn == 2){
                    num = 5;
                }else if(btn == 3){
                    num = 7;
                }
            }else if("开".equals(tyckg) && "开".equals(jmkg) && "关".equals(fmkg)) {
                if(btn == 0){
                    num = 1;
                }else if(btn == 1){
                    num = 3;
                }else if(btn == 2){
                    num = 5;
                }
            }else if("开".equals(tyckg) && "关".equals(jmkg) && "开".equals(fmkg)) {
                if(btn == 0){
                    num = 1;
                }else if(btn == 1){
                    num = 3;
                }else if(btn == 2){
                    num = 7;
                }
            }else if("关".equals(tyckg) && "开".equals(jmkg) && "开".equals(fmkg)) {
                if(btn == 0){
                    num = 1;
                }else if(btn == 1){
                    num = 5;
                }else if(btn == 2){
                    num = 7;
                }
            }else if("关".equals(tyckg) && "关".equals(jmkg) && "开".equals(fmkg)) {
                if(btn == 0){
                    num = 1;
                }else if(btn == 1){
                    num = 7;
                }
            }else if("关".equals(tyckg) && "开".equals(jmkg) && "关".equals(fmkg)) {
                if(btn == 0){
                    num = 1;
                }else if(btn == 1){
                    num = 5;
                }
            }else if("开".equals(tyckg) && "关".equals(jmkg) && "关".equals(fmkg)) {
                if(btn == 0){
                    num = 1;
                }else if(btn == 1){
                    num = 3;
                }
            }else if("关".equals(tyckg) && "关".equals(jmkg) && "关".equals(fmkg)) {
                if(btn == 0){
                    num = 1;
                }
            }
        }else{
            buffer.append("inkImg/hongmu/soaringSkill/B");
            if("开".equals(jmkg) && "开".equals(fmkg)) {
                if(btn == 0){
                    num = 63;
                }else if(btn == 1){
                    num = 65;
                }else if(btn == 2){
                    num = 323;
                }else if(btn == 3){
                    num = 325;
                }
            }else if("开".equals(jmkg) && "关".equals(fmkg)) {
                if(btn == 0){
                    num = 63;
                }else if(btn == 1){
                    num = 65;
                }else if(btn == 2){
                    num = 323;
                }
            }else if("关".equals(jmkg) && "开".equals(fmkg)) {
                if(btn == 0){
                    num = 63;
                }else if(btn == 1){
                    num = 65;
                }else if(btn == 2){
                    num = 325;
                }
            }else if("关".equals(jmkg) && "关".equals(fmkg)) {
                if(btn == 0){
                    num = 63;
                }else if(btn == 1){
                    num = 65;
                }
            }
        }
        if (!is) {
            num++;
        }
        buffer.append(num + ".png");
        return buffer.toString();
    }

    public SkillSMGatePanel getDivisionGatePanel() {
        return divisionGatePanel;
    }

    public void setDivisionGatePanel(SkillSMGatePanel divisionGatePanel) {
        this.divisionGatePanel = divisionGatePanel;
    }

    public CharacterMeridiansMainJpanel getMeridiansMainJpanel() {
        return meridiansMainJpanel;
    }

    public void setMeridiansMainJpanel(CharacterMeridiansMainJpanel meridiansMainJpanel) {
        this.meridiansMainJpanel = meridiansMainJpanel;
    }

    public int getTypeBtn() {
        return typeBtn;
    }

    public void setTypeBtn(int typeBtn) {
        this.typeBtn = typeBtn;
    }
    
}
